package server;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * The main class of the server; execute to start the server.
 * 
 * @author Lukas
 *
 */
public class Server {
	/**
	 * @param args Number of port.
	 */
	public static void main(String[] args) {
		if (args.length != 1) {
			System.out.println("Usage: java Server <port>");
			return;
		}
		NetworkService service = null;
		try {
			service = new NetworkService(Integer.parseInt(args[0]), 6);
			(new Thread(service)).start();
		} catch (NumberFormatException e) {
			System.out.println("Usage: java Server <port>");
			System.out.println("<port> must be a number");
			return;
		} catch (IOException e) {
			System.err.println("Could not create service");
			return;
		}
		try {
	        BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
	        stdIn.readLine();
		} catch (IOException e) {
			System.out.println("input exception");
		}
		try {
			service.serverSocket.close();
		} catch (IOException e) {
			System.err.println("Could not close server socket");
		}
	}

}
